/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.GUI;

import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract;
import edu.nii.qlks.ControlLayer.BCDoanhThuControl;
import edu.nii.qlks.ControlLayer.CTBCDoanhThuControl;
import edu.nii.qlks.ControlLayer.LoaiPhongControl;
import edu.nii.qlks.DataTransferObject.BCDoanhThuInfo;
import edu.nii.qlks.DataTransferObject.CTBCDoanhThuInfo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author MARS_NHO
 */
public class jfrm_BaoCaoDoanhThu extends javax.swing.JInternalFrame {
    
    BCDoanhThuControl BCDoanhThuCT;
    BCDoanhThuInfo BCDoanhThuInfo;
    CTBCDoanhThuControl CTBCDoanhThuCT;
    CTBCDoanhThuInfo CTBCDoanhThuInfo;
    LoaiPhongControl loaiPhongCT;
    
    /**
     * Creates new form jfrm_BaoCaoDoanhThu
     */
    public jfrm_BaoCaoDoanhThu() {
        initComponents();
        
        BCDoanhThuCT = new BCDoanhThuControl();
        BCDoanhThuInfo = new BCDoanhThuInfo();
        CTBCDoanhThuCT = new CTBCDoanhThuControl();
        CTBCDoanhThuInfo = new CTBCDoanhThuInfo();
        loaiPhongCT = new LoaiPhongControl();
        
        jXTable_LoaiPhong.getColumnModel().getColumn(0).setPreferredWidth(5);
        jXTable_LoaiPhong.getColumnModel().getColumn(1).setPreferredWidth(150);
        jXTable_LoaiPhong.getColumnModel().getColumn(2).setPreferredWidth(50);
        jXTable_LoaiPhong.getColumnModel().getColumn(3).setPreferredWidth(50);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel_Nen = new javax.swing.JPanel();
        jXPanel_ThongTinBaoCao = new org.jdesktop.swingx.JXPanel();
        jXLabel_ThangBaoCao = new org.jdesktop.swingx.JXLabel();
        jXLabel_NamBaoCao = new org.jdesktop.swingx.JXLabel();
        jComboBox_ThangBaoCao = new javax.swing.JComboBox();
        jComboBox_NamBaoCao = new javax.swing.JComboBox();
        jXLabel_TongDoanhThu = new org.jdesktop.swingx.JXLabel();
        jXTextField_TongDoanhThu = new org.jdesktop.swingx.JXTextField();
        jXPanel_ChiTietBaoCao = new org.jdesktop.swingx.JXPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTable_LoaiPhong = new org.jdesktop.swingx.JXTable();
        jXLabel_TieuDe = new org.jdesktop.swingx.JXLabel();
        jXButton_LamMoi = new org.jdesktop.swingx.JXButton();
        jXButton_LapBC = new org.jdesktop.swingx.JXButton();
        jXButton_Thoat = new org.jdesktop.swingx.JXButton();
        jButton_InBaoCao = new javax.swing.JButton();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setTitle("Báo cáo doanh thu");

        jPanel_Nen.setBackground(new java.awt.Color(255, 255, 255));

        jXPanel_ThongTinBaoCao.setBackground(new java.awt.Color(255, 255, 255));
        jXPanel_ThongTinBaoCao.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin báo cáo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        jXLabel_ThangBaoCao.setText("Tháng báo cáo");
        jXLabel_ThangBaoCao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jXLabel_NamBaoCao.setText("Năm báo cáo");
        jXLabel_NamBaoCao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jComboBox_ThangBaoCao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBox_ThangBaoCao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));

        jComboBox_NamBaoCao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBox_NamBaoCao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2013", "2014", "2015" }));

        jXLabel_TongDoanhThu.setText("Tổng doanh thu");
        jXLabel_TongDoanhThu.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jXTextField_TongDoanhThu.setEditable(false);
        jXTextField_TongDoanhThu.setBackground(new java.awt.Color(255, 255, 255));
        jXTextField_TongDoanhThu.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout jXPanel_ThongTinBaoCaoLayout = new javax.swing.GroupLayout(jXPanel_ThongTinBaoCao);
        jXPanel_ThongTinBaoCao.setLayout(jXPanel_ThongTinBaoCaoLayout);
        jXPanel_ThongTinBaoCaoLayout.setHorizontalGroup(
            jXPanel_ThongTinBaoCaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel_ThongTinBaoCaoLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(jXPanel_ThongTinBaoCaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jXLabel_ThangBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel_NamBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jXPanel_ThongTinBaoCaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBox_NamBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jXPanel_ThongTinBaoCaoLayout.createSequentialGroup()
                        .addComponent(jComboBox_ThangBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(132, 132, 132)
                        .addComponent(jXLabel_TongDoanhThu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jXTextField_TongDoanhThu, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(116, Short.MAX_VALUE))
        );
        jXPanel_ThongTinBaoCaoLayout.setVerticalGroup(
            jXPanel_ThongTinBaoCaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel_ThongTinBaoCaoLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jXPanel_ThongTinBaoCaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel_ThangBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_ThangBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel_TongDoanhThu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXTextField_TongDoanhThu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanel_ThongTinBaoCaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel_NamBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_NamBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jXPanel_ChiTietBaoCao.setBackground(new java.awt.Color(255, 255, 255));
        jXPanel_ChiTietBaoCao.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Chi tiết báo cáo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
        jXPanel_ChiTietBaoCao.setLayout(new java.awt.BorderLayout());

        jXTable_LoaiPhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "Loại Phòng", "Doanh Thu", "Tỷ lệ"
            }
        ));
        jScrollPane2.setViewportView(jXTable_LoaiPhong);

        jXPanel_ChiTietBaoCao.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jXLabel_TieuDe.setText("BÁO CÁO DOANH THU THEO LOẠI PHÒNG");
        jXLabel_TieuDe.setFocusable(false);
        jXLabel_TieuDe.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

        jXButton_LamMoi.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/refresh.png"))); // NOI18N
        jXButton_LamMoi.setText("Làm mới");
        jXButton_LamMoi.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_LamMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_LamMoiActionPerformed(evt);
            }
        });

        jXButton_LapBC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N
        jXButton_LapBC.setText("Lập báo cáo");
        jXButton_LapBC.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_LapBC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_LapBCActionPerformed(evt);
            }
        });

        jXButton_Thoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit_16.png"))); // NOI18N
        jXButton_Thoat.setText("Thoát");
        jXButton_Thoat.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_Thoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_ThoatActionPerformed(evt);
            }
        });

        jButton_InBaoCao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton_InBaoCao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/baocao.png"))); // NOI18N
        jButton_InBaoCao.setText("In báo cáo");
        jButton_InBaoCao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_InBaoCaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel_NenLayout = new javax.swing.GroupLayout(jPanel_Nen);
        jPanel_Nen.setLayout(jPanel_NenLayout);
        jPanel_NenLayout.setHorizontalGroup(
            jPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_NenLayout.createSequentialGroup()
                .addGroup(jPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel_NenLayout.createSequentialGroup()
                        .addGap(237, 237, 237)
                        .addComponent(jXLabel_TieuDe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel_NenLayout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addGroup(jPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jXPanel_ChiTietBaoCao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jXPanel_ThongTinBaoCao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(49, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_NenLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton_InBaoCao)
                .addGap(33, 33, 33)
                .addComponent(jXButton_LamMoi, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addComponent(jXButton_LapBC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(jXButton_Thoat, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63))
        );
        jPanel_NenLayout.setVerticalGroup(
            jPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_NenLayout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jXLabel_TieuDe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXPanel_ThongTinBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXPanel_ChiTietBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42)
                .addGroup(jPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jXButton_Thoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXButton_LapBC, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXButton_LamMoi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton_InBaoCao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        getContentPane().add(jPanel_Nen, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jXButton_LapBCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_LapBCActionPerformed
        // TODO add your handling code here:
        
        if (jComboBox_ThangBaoCao.getSelectedItem().toString().trim().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn tháng cần báo cáo!");
            return;
        }
        
        if (jComboBox_NamBaoCao.getSelectedItem().toString().trim().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn năm cần báo cáo!");
            return;
        }
        Vector vt = new Vector();
        String str = "";
        float TongDoanhThu = 0;
        try {
            //LAY THONG TIN BAO CAO DOANH THU
            vt = BCDoanhThuCT.LayDS();
            if (vt.size() > 0) {
                Vector vt_row = (Vector) vt.get(vt.size() - 1);
                str = vt_row.get(0).toString().trim();
                BCDoanhThuInfo.setMaBaoCaoDoanhThu(BCDoanhThuCT.TaoMaTuDong(str, 5));
            } else {
                BCDoanhThuInfo.setMaBaoCaoDoanhThu(BCDoanhThuCT.TaoMaTuDong("MBCDT000", 5));
            }
            str = jComboBox_ThangBaoCao.getSelectedItem().toString().trim();
            int thangBaoCao = Integer.parseInt(str);
            BCDoanhThuInfo.setThangBaoCao(thangBaoCao);
            str = jComboBox_NamBaoCao.getSelectedItem().toString().trim();
            int namBaoCao = Integer.parseInt(str);
            BCDoanhThuInfo.setNamBaoCao(namBaoCao);
            
            
            vt = loaiPhongCT.LayDS();
            if (vt.size() > 0){
                for (int i = 0; i < vt.size(); i++){
                    Vector vt_row = (Vector)vt.get(i);
                    String maLoaiPhong = vt_row.get(0).toString().trim();
                    System.out.println("ma loai phong: "+maLoaiPhong+":");
                    String thangBC = jComboBox_ThangBaoCao.getSelectedItem().toString().trim();
                    System.out.println("thang bao cao: "+thangBC+":");
                    int thang = Integer.parseInt(thangBC);
                    System.out.println("thang bao cao: "+(thang+1));
                    String namBC = jComboBox_NamBaoCao.getSelectedItem().toString().trim();
                    int nam = Integer.parseInt(namBC);
                    Vector _vt = BCDoanhThuCT.LayDS_MaLoaiPhong(maLoaiPhong, thang, nam);
                    System.out.println("size: "+_vt.size());
                    if (_vt.size() > 0){
                        for (int j = 0; j < _vt.size(); j++){
                            Vector _vt_row = (Vector)_vt.get(j);
                            String thanhTien = _vt_row.get(2).toString().trim();
                            System.out.println("thanh tien: "+thanhTien);
                            float doanhThu = Float.parseFloat(thanhTien);
                            TongDoanhThu = TongDoanhThu + doanhThu;
                            System.out.println("tong doanh thu: "+TongDoanhThu);
                        }
                    }
                }
            }
            
            
            vt = loaiPhongCT.LayDS();
            if (vt.size() > 0){
                for (int i = 0; i < vt.size(); i++){
                    float doanhThu_LoaiPhong = 0;
                    Vector vt_row = (Vector)vt.get(i);
                    String maLoaiPhong = vt_row.get(0).toString().trim();
                    System.out.println("ma loai phong: "+maLoaiPhong+":");
                    String tenLoaiPhong = vt_row.get(1).toString().trim();
                    System.out.println("ten loai phong: "+tenLoaiPhong+":");
                    String thangBC = jComboBox_ThangBaoCao.getSelectedItem().toString().trim();
                    System.out.println("thang bao cao: "+thangBC+":");
                    int thang = Integer.parseInt(thangBC);
                    System.out.println("thang bao cao: "+(thang+1));
                    String namBC = jComboBox_NamBaoCao.getSelectedItem().toString().trim();
                    int nam = Integer.parseInt(namBC);
                    Vector _vt = BCDoanhThuCT.LayDS_MaLoaiPhong(maLoaiPhong, thang, nam);
                    System.out.println("size: "+_vt.size());
                    if (_vt.size() > 0){
                        for (int j = 0; j < _vt.size(); j++){
                            Vector _vt_row = (Vector)_vt.get(j);
                            String thanhTien = _vt_row.get(2).toString().trim();
                            System.out.println("thanh tien: "+thanhTien);
                            float doanhThu = Float.parseFloat(thanhTien);
                            doanhThu_LoaiPhong = doanhThu_LoaiPhong + doanhThu;
                            System.out.println("tong doanh thu: "+doanhThu_LoaiPhong);
                        }
                    }
                    
                    Vector vt_CT = CTBCDoanhThuCT.LayDS();
                    if (vt_CT.size() > 0){
                        Vector vt_CT_row = (Vector)vt_CT.get(vt_CT.size() - 1);
                        String ma = vt_CT_row.get(0).toString().trim();
                        CTBCDoanhThuInfo.setMaChiTietBaoCaoDoanhThu(CTBCDoanhThuCT.TaoMaTuDong(ma, 7));
                    }
                    else{
                        CTBCDoanhThuInfo.setMaChiTietBaoCaoDoanhThu(CTBCDoanhThuCT.TaoMaTuDong("MCTBCDT000", 7));
                    }
                    CTBCDoanhThuInfo.setMaBaoCaoDoanhThu(BCDoanhThuInfo.getMaBaoCaoDoanhThu());
                    CTBCDoanhThuInfo.setDoanhThu(doanhThu_LoaiPhong);
                    if (TongDoanhThu == 0){
                        CTBCDoanhThuInfo.setTyLe(0);
                    }
                    else{
                        CTBCDoanhThuInfo.setTyLe(doanhThu_LoaiPhong/TongDoanhThu);
                    }
                    CTBCDoanhThuInfo.setMaLoaiPhong(maLoaiPhong);    
                    
                    //INSERT CHI TIET BAO CAO DOANH THU
                    CTBCDoanhThuCT.Insert(CTBCDoanhThuInfo);
                    
                    //CAP NHAT LEN JTABLE      
                    Object[] add = {i+1, tenLoaiPhong, CTBCDoanhThuInfo.getDoanhThu(), CTBCDoanhThuInfo.getTyLe()};
                    ((DefaultTableModel)jXTable_LoaiPhong.getModel()).addRow(add);

                }
            }
            
            jXTextField_TongDoanhThu.setText(String.valueOf(TongDoanhThu));
            
            //INSERT BAO CAO DOANH THU
            BCDoanhThuCT.Insert(BCDoanhThuInfo);
            JOptionPane.showMessageDialog(rootPane, "Thêm thành công!");
            
            
            //UPDATE NUT LAP BAO CAO = FALSE
            jXButton_LapBC.setEnabled(false);
            
        } catch (Exception ex) {
            Logger.getLogger(jfrm_BaoCaoDoanhThu.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jXButton_LapBCActionPerformed

    private void jXButton_ThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_ThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jXButton_ThoatActionPerformed

    private void jXButton_LamMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_LamMoiActionPerformed
        jXButton_LapBC.setEnabled(true);
        jXTextField_TongDoanhThu.setText(null);
        jComboBox_ThangBaoCao.setSelectedIndex(0);
        jComboBox_NamBaoCao.setSelectedIndex(0);
        jXTable_LoaiPhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                
            },
            new String [] {
                "STT", "Loại Phòng", "Doanh Thu", "Tỷ Lệ"
            }
        ));
    }//GEN-LAST:event_jXButton_LamMoiActionPerformed

    
    
    private void jButton_InBaoCaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_InBaoCaoActionPerformed
        try {
            JasperDesign jasDesign = JRXmlLoader.load("src\\edu\\nii\\qlks\\GUI\\JasperReport\\rptBaoCaoDoanhThuTheoLoaiPhong.jrxml");
                JasperReport jasReport = JasperCompileManager.compileReport(jasDesign);
                JasperPrint jasPrint = JasperFillManager.fillReport(jasReport, null, BusinessLogicAbstract.LayKetNoi());
                JasperViewer.viewReport(jasPrint,false);
        } catch (JRException ex) {
            Logger.getLogger(jfrm_BaoCaoDoanhThu.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton_InBaoCaoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_InBaoCao;
    private javax.swing.JComboBox jComboBox_NamBaoCao;
    private javax.swing.JComboBox jComboBox_ThangBaoCao;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel_Nen;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.swingx.JXButton jXButton_LamMoi;
    private org.jdesktop.swingx.JXButton jXButton_LapBC;
    private org.jdesktop.swingx.JXButton jXButton_Thoat;
    private org.jdesktop.swingx.JXLabel jXLabel_NamBaoCao;
    private org.jdesktop.swingx.JXLabel jXLabel_ThangBaoCao;
    private org.jdesktop.swingx.JXLabel jXLabel_TieuDe;
    private org.jdesktop.swingx.JXLabel jXLabel_TongDoanhThu;
    private org.jdesktop.swingx.JXPanel jXPanel_ChiTietBaoCao;
    private org.jdesktop.swingx.JXPanel jXPanel_ThongTinBaoCao;
    private org.jdesktop.swingx.JXTable jXTable_LoaiPhong;
    private org.jdesktop.swingx.JXTextField jXTextField_TongDoanhThu;
    // End of variables declaration//GEN-END:variables
}
